Ext.define('Era.view.MenuItems',{
    extend: 'Ext.container.Container',
    alias: 'widget.menuitems',
    layout: 'vbox',
    width: 100,
    height: 300,
    
    items: [
        {
            xtype: 'button',
            text: 'New Event',
            width: 100,
            scale: 'medium',
            margin: '0 0 1 0',
            handler: function() {
                
                var record = new Era.model.Event();
                
                var screen = Ext.create('Era.view.EventScreen',{
                    buttons: [
                        {
                            text: 'Submit',
                            handler: function() {
                                
                                // update the record
                                this.findParentByType('eventscreen').getForm().updateRecord(record);
                                
                                // add to database
                                Era.controller.Main.getStore('events').add(record);
                                
                                // create a grid with all events
                                var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore('events')});

                                // load grid in the menu panel
                                Era.controller.Main.showMenuScreen(screen);
                            }
                        },
                        {
                            text: 'Cancel',
                            handler: function() {

                                // create a grid with all events
                                var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore()});

                                // load grid in the menu panel
                                Era.controller.Main.showMenuScreen(screen);
                            }
                        }
                    ]
                });
                 
                // load record in the form 
                screen.loadRecord(record);
                
                // load form in the menu panel
                Era.controller.Main.showMenuScreen(screen);
            }
        },
        {
            xtype: 'button',
            text: 'Manage Events',
            width: 100,
            scale: 'medium',
            margin: '0 0 1 0',
            handler: function() {
                
                // create a grid with all events
                var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore('events')});
                
                
                /*screen.getStore().filterBy(function(record,id) {
                    
                    
                    var limit = new Date(2012,1,10);
                    var value = record.get('start_date');
                    
                    console.log(limit.getTime());
                    console.log(value.getTime());
                    console.log('--------');
                    if (value > limit ) {
                        return true;
                    }
                    
                    return false;
                    
                });*/
               
                // load grid in the menu panel
                Era.controller.Main.showMenuScreen(screen);
            }
        },
        {
            xtype: 'button',
            text: 'Timeline',
            disabled: true,
            width: 100,
            scale: 'medium',
            margin: '0 0 0 0',
            handler: function() {
                
            }
        },
        {
            xtype: 'button',
            text: 'Gallery',
            disabled: true,
            width: 100,
            scale: 'medium',
            margin: '0 0 1 0',
            handler: function() {

            }
        },
        {
            xtype: 'button',
            text: 'About Us',
            disabled: true,
            width: 100,
            scale: 'medium',
            margin: '0 0 1 0',
            handler: function() {

            }
        }
    ]
});